import { _decorator, Component, v3 } from 'cc';
import { GRoot, UIPackage } from 'fairygui-cc';
import Res from './fwk/Managers/Res';
import { RegistPMVC } from './fwk/puremvc/RegistFunc';
import { Defer } from './fwk/Utils/Defer';
import { StartGameCMD, TickCMD } from './Game/GamePuremvc/Command/GameCMD';
import { GameFacade } from './fwk/puremvc/GameFacade';
const { ccclass, property } = _decorator;
@ccclass('Launch')
export class Launch extends Component {
    @property
    isInitFui = true;
    loadDefer: Defer = new Defer();
    protected async onLoad() {
        this.loadDefer = new Defer();
        await Res.init();
        if (this.isInitFui)
            await this.initFui();
        await RegistPMVC.excuteFunc();
        this.loadDefer.resolve();
        this.startGame()
        //初始化游戏框架（资源管理模块，网络模块，协议模块，日志模块）
    }
    startGame() {
        //资源检测更新
        GameFacade.send(StartGameCMD);
    }
    async initFui() {
        let defer = new Defer();
        GRoot.create();
        GRoot.inst.visible = true;
        GRoot.inst.setPivot(0.5, 0.5, true);
        GRoot.inst.node.position = v3();
        UIPackage.loadPackage("fui/Common", (err, pkg) => {
            if (err) {
                console.error(err);
                defer.reject();
            } else {
                defer.resolve();
            }

        })
        await defer.promise;
    }
    update(deltaTime: number) {
        if (!RegistPMVC.isExecuted)
            return;
        GameFacade.send(TickCMD, deltaTime);
    }
}


